<template>
  <div class="app-container">
    <div class="box-container" style="width: 600px;">
      <div style="font-size: 16px; font-weight: bolder; margin-bottom: 15px;">进修咨询</div>
      <el-form ref="form" :model="form" :rules="rules" label-width="80px">
        <el-form-item label="联系人" prop="contactMan">
          <el-input v-model="form.contactMan" placeholder="请输入联系人"/>
        </el-form-item>
        <el-form-item label="联系电话" prop="contactPhone">
          <el-input v-model="form.contactPhone" placeholder="请输入联系电话"/>
        </el-form-item>
        <el-form-item label="技术电话" prop="email">
          <el-input v-model="form.email" placeholder="请输入技术电话"/>
        </el-form-item>
        <el-form-item label="地址" prop="address">
          <el-input v-model="form.address" placeholder="请输入地址"/>
        </el-form-item>
        <el-form-item label="邮编" prop="zipCode">
          <el-input v-model="form.zipCode" placeholder="请输入邮编"/>
        </el-form-item>
        <!-- <el-form-item label="传真" prop="fax">
          <el-input v-model="form.fax" placeholder="请输入传真"/>
        </el-form-item> -->
        <el-form-item>
          <el-button type="primary" @click="submitForm">保 存</el-button>
        </el-form-item>
      </el-form>
    </div>
  </div>
</template>

<script>
import { getContactInfo, updateContactInfo } from '@/api/business/contactInfo'

export default {
  name: 'ContactInfo',
  data() {
    return {
      // 根路径
      baseURL: process.env.VUE_APP_BASE_API,
      // 表单参数
      form: {},
      // 表单校验
      rules: {
        id: [
          { required: true, message: '主键不能为空', trigger: 'blur' }
        ],
        contactMan: [
          { required: true, message: '联系人不能为空', trigger: 'blur' }
        ],
        contactPhone: [
          { required: true, message: '联系电话不能为空', trigger: 'blur' }
        ],
        email: [
          { required: true, message: '邮箱不能为空', trigger: 'blur' }
        ],
        address: [
          { required: true, message: '地址不能为空', trigger: 'blur' }
        ],
        zipCode: [
          { required: true, message: '邮编不能为空', trigger: 'blur' }
        ],
        fax: [
          { required: true, message: '传真不能为空', trigger: 'blur' }
        ]
      }
    }
  },
  created() {
    getContactInfo(1).then(response => {
      if (response.data) {
        this.form = response.data
      } else {
        this.form = {
          id: 1,
          contactMan: null,
          contactPhone: null,
          email: null,
          address: null,
          zipCode: null,
          fax: null,
        }
      }
    })
  },
  methods: {
    /** 提交按钮 */
    submitForm() {
      this.$refs['form'].validate(valid => {
        if (valid) {
          updateContactInfo(this.form).then(response => {
            this.$modal.msgSuccess('保存成功')
          })
        }
      })
    }
  }
}
</script>
